using System;

namespace TrueCode.Core.Validation
{
  public abstract class ValidateAttribute : Attribute
  {
    private readonly Type _exceptionType;
    private readonly object[] _arguments;
    private Exception _exception;

    protected ValidateAttribute() : this( null ){}
    protected ValidateAttribute( Type exceptionType )
    {
      _exceptionType = exceptionType;
    }

    protected ValidateAttribute( Type exceptionType, params object[] arguments )
    {
      _exceptionType = exceptionType;
      _arguments = arguments;
    }

    public Exception Exception
    {
      get
      {
        return _exception ??
               ( _exceptionType == null ? null : _exception = ( Exception )Activator.CreateInstance( _exceptionType, _arguments ) );
      }
    }

  }
}